package com.tiecode.javac9;

import com.rapid.toolchain.java.BaseJavaCompiler;
import com.rapid.toolchain.java.JavacOutputLogger;

import org.openjdk.tools.javac.main.Main;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

public class OpenJdk9Compiler extends BaseJavaCompiler {
    @Override
    public String getCompilerVersion() {
        return "9";
    }

    @Override
    public boolean compile(List<String> args, OnExecutionCallback callback) {
        JavacOutputLogger logger = new JavacOutputLogger(callback);
        Main.Result result = new Main("javac", new PrintWriter(logger)).compile(args.toArray(new String[0]));
        try {
            logger.close();
        } catch (IOException ignore) {
        }
        return result.isOK();
    }
}
